package com.gx.smart.building.ui.repair.fragment

import android.content.Intent
import android.view.ViewGroup
import com.gx.smart.building.R
import com.gx.smart.building.databinding.FragmentWaitingBinding
import com.gx.smart.building.ui.repair.RepairDetailActivity
import com.gx.smart.building.ui.repair.adapter.RepairRecordAdapter
import com.gx.smart.lib.http.api.response.WorkOrder

class WaitingFragment : CommonFragment() {
    private lateinit var viewBinding: FragmentWaitingBinding
    private lateinit var adapter: RepairRecordAdapter

    companion object {
        @JvmStatic
        fun newInstance() = WaitingFragment()
    }

    override fun onItemClick(e: WorkOrder, position: Int) {
        val intent = Intent(requireActivity(), RepairDetailActivity::class.java)
        intent.putExtra("id", e.id)
        startActivity(intent)
    }

    override fun onBindLayout(): Int = R.layout.fragment_waiting


    override fun initContentView(root: ViewGroup) {
        viewBinding = FragmentWaitingBinding.inflate(layoutInflater, root, true)
    }

    override fun initContent() {
        super.initContent()
        adapter = RepairRecordAdapter(activity)
        adapter.setItemClickListener(this)
        initView(viewBinding.recyclerView, adapter, viewBinding.refreshLayout)
    }

    override fun doAction() {
        viewModel.queryWorkOrderList(currentPage, listOf("task_receive"))
            .observe(viewLifecycleOwner) {
                handleResult(it)
            }
    }

    override fun onResume() {
        super.onResume()
        viewBinding.refreshLayout.autoRefresh()
    }
}